// @技能功能
const express = require('express');
const router = express.Router();
const bcrypt = require('bcryptjs');
const jwt = require('jsonwebtoken');
const keys = require('../../config/keys');
const passport = require('passport');
const Map = require('../../models/Map');
const Skill = require('../../models/Skill');
const open_api = require('../../controller/open_api');

// @route  GET api/skill/skill
// @desc   返回的请求的json数据
// @access public
router.get('/skill', (req, res) => {
    res.json({ msg: 'skill works' });
  });
  

// @route  Post api/skill/add
// @desc   新增技能
// @access public
router.post('/add', (req, res) => {
    Skill.findOne({ name: req.body.name }).then(skill => {
        if (skill) {
          return res.status(400).json('该技能已存在');
        } else {
            const SkillMap = {};
            if(req.body.name){SkillMap.name = req.body.name};
            if(req.body.info){SkillMap.info = req.body.info};
            if(req.body.ad){SkillMap.ad = req.body.ad};
            if(req.body.ap){SkillMap.ap = req.body.ap};

            new Skill(SkillMap).save()
            .then(skill => res.json(skill))
            .catch(err => console.log(err));
        }
    });
  });

// @route  GET api/maps/getMapInfo
// @desc   return all map info
// @access Private
//router.get('/getMapInfo', passport.authenticate('jwt', { session: false }),open_api.getMapInfo);
  

module.exports = router;
  